package com.mc.algorithm;

import java.util.Iterator;
import java.util.NavigableMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class QueryUpdate {
	public static void execute(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		NavigableMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
		for(int i=1;i<=n;i++){
			map.put(i, sc.nextInt());
		}
		for(int j=0;j<m;j++){
			String ch = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if("Q".equals(ch)){
				NavigableMap<Integer,Integer> smap = map.subMap(a,true, b,true);
				Set<Integer> keyset = smap.keySet();
				Iterator<Integer> iter = keyset.iterator();
				int max = Integer.MIN_VALUE;
				while(iter.hasNext()){
					int key = iter.next();
					if(smap.get(key)>max)
						max = smap.get(key);
				}
				System.out.println(max);
			}
			else{
				map.put(a, b);
			}
		}
	}
	public static void main(String[] args) {
		QueryUpdate.execute();
	}
}
